/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package medicalassistant;
import java.sql.*;
/**
 *
 * @author Thomas
 */
public class MedicalAssistantWindow extends javax.swing.JFrame {

    /**
     * Creates new form MedicalAssistantWindow
     */
    public MedicalAssistantWindow(int ID, int userType, Connection connect) {
        initComponents();
        ResultSet name = null;
        try {
            Class.forName("org.sqlite.JDBC");
            conn = connect;
            stat = conn.createStatement();
            switch (userType) {
                case 0: name = stat.executeQuery("SELECT first, last FROM patients WHERE uid = '" + ID + "';"); break;
                case 1: name = stat.executeQuery("SELECT first, last FROM nurses WHERE uid = '" + ID + "';"); break;
                case 2: name = stat.executeQuery("SELECT first, last FROM doctors WHERE uid = '" + ID + "';"); break;
            }
            if (name != null)
                welcomeMessage.setText("Welcome, " + name.getString("first") + " " + name.getString("last") + "! [" + ID + "]");
            else
                welcomeMessage.setText("Welcome, administrator.");
        } catch(ClassNotFoundException ex) {System.out.println(ex.getMessage());}
        catch(SQLException ex) {System.out.println(ex.getMessage());}
        // BEGIN ADDING TABS
        switch(userType) {
            case 0:     // Patient
                MyHealthPanel myHealth = new MyHealthPanel(ID, userType, conn);
                tabs.add(myHealth, "My Health");
                break;
            case 3:     // Admin
                ManageDoctor manageDoctor = new ManageDoctor(ID, userType, conn);
                doctorSelect.add(manageDoctor, "Manage Doctors");
                AddDoctorPanel addDoctor = new AddDoctorPanel(ID, userType, conn);
                doctorSelect.add(addDoctor, "Add New Doctor");
                tabs.add(doctorSelect, "Doctors");
            case 2:     // Doctor
                ManageNurser manageNurse = new ManageNurser(ID, userType, conn);
                nurseSelect.add(manageNurse, "Manage Nurses");
                AddNursePanel addNurse = new AddNursePanel(ID, userType, conn);
                nurseSelect.add(addNurse, "Add New Nurse");
                tabs.add(nurseSelect, "Nurses");
                
            case 1:     // Nurse
                ManagePatient managePatient = new ManagePatient(ID, userType, conn);
                patientSelect.add(managePatient, "Manage Patients");
                if (userType > 1) {
                    AddPatientPanel addPatient = new AddPatientPanel(ID, userType, conn);
                    patientSelect.add(addPatient, "Add New Patient");
                }
                tabs.add(patientSelect, "Patients");
                break;
        }
        
        // Add Manage Account tab
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        doctorTab = new javax.swing.JPanel();
        doctorSelect = new javax.swing.JTabbedPane();
        nurseTab = new javax.swing.JPanel();
        nurseSelect = new javax.swing.JTabbedPane();
        patientTab = new javax.swing.JPanel();
        patientSelect = new javax.swing.JTabbedPane();
        tabs = new javax.swing.JTabbedPane();
        welcome = new javax.swing.JPanel();
        hospitalName = new javax.swing.JLabel();
        welcomeMessage = new javax.swing.JLabel();
        logoutButton = new javax.swing.JButton();

        doctorTab.setLayout(new java.awt.GridLayout(1, 0));
        doctorTab.add(doctorSelect);

        nurseTab.setLayout(new java.awt.GridLayout(1, 0));
        nurseTab.add(nurseSelect);

        patientTab.setLayout(new java.awt.GridLayout(1, 0));
        patientTab.add(patientSelect);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(1024, 768));
        getContentPane().setLayout(new java.awt.GridLayout(1, 0));

        welcome.setLayout(new java.awt.GridBagLayout());

        hospitalName.setFont(new java.awt.Font("Tahoma", 0, 24)); // NOI18N
        hospitalName.setText("Mercy Hospital");
        welcome.add(hospitalName, new java.awt.GridBagConstraints());

        welcomeMessage.setText("Welcome, John Doe.");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        welcome.add(welcomeMessage, gridBagConstraints);

        logoutButton.setText("Logout");
        logoutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logoutButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        welcome.add(logoutButton, gridBagConstraints);

        tabs.addTab("Main", welcome);

        getContentPane().add(tabs);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void logoutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutButtonActionPerformed
        System.exit(0);
    }//GEN-LAST:event_logoutButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    /*public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        /*try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MedicalAssistantWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MedicalAssistantWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MedicalAssistantWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MedicalAssistantWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }*/
        //</editor-fold>

        /* Create and display the form */
        /*java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MedicalAssistantWindow().setVisible(true);
            }
        });
    }*/
    // SQLite Variable declaration
    private Connection conn;
    private Statement stat;
    // End of SQLite Variable declaration
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane doctorSelect;
    private javax.swing.JPanel doctorTab;
    private javax.swing.JLabel hospitalName;
    private javax.swing.JButton logoutButton;
    private javax.swing.JTabbedPane nurseSelect;
    private javax.swing.JPanel nurseTab;
    private javax.swing.JTabbedPane patientSelect;
    private javax.swing.JPanel patientTab;
    private javax.swing.JTabbedPane tabs;
    private javax.swing.JPanel welcome;
    private javax.swing.JLabel welcomeMessage;
    // End of variables declaration//GEN-END:variables
}
